package com.sg.business.commons.ui.work;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;

import com.mobnut.commons.html.HtmlUtil;
import com.mobnut.db.model.PrimaryObject;
import com.sg.business.commons.editingsupport.WorkDelDocEditingSupportor;
import com.sg.business.commons.editingsupport.WorkEditDocEditingSupportor;
import com.sg.business.commons.editingsupport.WorkSettingDeliEditingSupportor;
import com.sg.business.commons.editingsupport.WorkViewDocEditingSupportor;
import com.sg.business.commons.labelprovider.work.WorkDelDocHtmlLabel;
import com.sg.business.commons.labelprovider.work.WorkEditDocHtmlLabel;
import com.sg.business.commons.labelprovider.work.WorkSettingDeliHtmlLabel;
import com.sg.business.commons.labelprovider.work.WorkViewDocHtmlLabel;
import com.sg.business.model.Work;
import com.sg.widgets.part.CurrentAccountContext;

public class OutputDeliveryBlockTab extends AbstractDeliveryBlock {

	private static final String WORK_WORKDELIVERY_OUTPUT = "work.workdelivery.output";

	public OutputDeliveryBlockTab(Composite parent, PrimaryObject master) {
		super(parent, master);
		createControl(parent, WORK_WORKDELIVERY_OUTPUT, false);
	}

	@Override
	protected TableViewer createViewerContent(Composite parent,
			String configuratorId) {
		TableViewer viewer = super.createViewerContent(parent, configuratorId);
		HtmlUtil.enableMarkup(viewer.getControl());
		createColumn(viewer);
		return viewer;
	}

	private void createColumn(TableViewer viewer) {
		TableViewerColumn column = new TableViewerColumn(viewer, SWT.CENTER);
		column.getColumn().setWidth(20);
		column.setLabelProvider(new WorkViewDocHtmlLabel());
		column.setEditingSupport(new WorkViewDocEditingSupportor()
				.createEditingSupport(viewer, column, null));

		column = new TableViewerColumn(viewer, SWT.CENTER);
		column.getColumn().setWidth(20);
		column.setLabelProvider(new WorkEditDocHtmlLabel());
		column.setEditingSupport(new WorkEditDocEditingSupportor()
				.createEditingSupport(viewer, column, null));

		column = new TableViewerColumn(viewer, SWT.CENTER);
		column.getColumn().setWidth(20);
		column.setLabelProvider(new WorkDelDocHtmlLabel());
		column.setEditingSupport(new WorkDelDocEditingSupportor()
				.createEditingSupport(viewer, column, null));

		if (((Work) master).canEditDeliverable(new CurrentAccountContext())) {
			column = new TableViewerColumn(viewer, SWT.CENTER);
			column.getColumn().setWidth(20);
			column.setLabelProvider(new WorkSettingDeliHtmlLabel());
			column.setEditingSupport(new WorkSettingDeliEditingSupportor()
					.createEditingSupport(viewer, column, null));
		}
	}
}
